﻿using System;
using System.Runtime.Serialization;

namespace LoveEat.MODEL.WeChat
{
    /// <summary>
    ///     自定义微信错误EXCEPTION
    /// </summary>
    public class WxErrorMsgException : Exception
    {
        /// <summary>
        ///     初始化自定义异常的新实例
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="operater">操作函数</param>
        /// <param name="exceptionTye">自定义异常类型</param>
        public WxErrorMsgException(string message, WxErrorMsgExceptionType exceptionTye)
            : base(message)
        {
            ExceptionType = exceptionTye;
        }

        /// <summary>
        ///     初始化自定义异常的新实例
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="innerException">内部异常</param>
        /// <param name="operater">操作函数</param>
        /// <param name="exceptionTye">导致当前异常的异常</param>
        public WxErrorMsgException(string message, Exception innerException, WxErrorMsgExceptionType exceptionTye)
            : base(message, innerException)
        {
            ExceptionType = exceptionTye;
        }

        /// <summary>
        ///     自定义异常类型
        /// </summary>
        public WxErrorMsgExceptionType ExceptionType { get; private set; }

        /// <summary>
        ///     获取描述异常的消息
        /// </summary>
        public override string Message
        {
            get
            {
                if (ExceptionType == WxErrorMsgExceptionType.WxErrorException)
                {
                    return base.Message;
                }
                return string.Format("异常：{1} InnerException:{2}", base.Message,
                    base.InnerException == null ? "null" : base.InnerException.Message);
            }
        }
    }

    /// <summary>
    ///     自定义异常类型枚举
    /// </summary>
    [DataContract]
    [Serializable]
    public enum WxErrorMsgExceptionType
    {
        /// <summary>
        ///     微信错误
        /// </summary>
        [EnumMember] WxErrorException = 0,

        /// <summary>
        ///     悟空自定义错误
        /// </summary>
        [EnumMember] WkCustomerException = 1
    }
}